package com.my.behaviourtype.chain.nohierarchy;

import java.util.ArrayList;
import java.util.List;

public class FilterManager implements FilterChain {
	private List<Filter> filters = new ArrayList<Filter>();
	private int index = 0;
	
	public void add(Filter filter) {
		this.filters.add(filter);
	}
	
	public void remove(Filter filter) {
		this.filters.remove(filter);
	}
	
	public void doFilter(StringBuffer request, StringBuffer response) {
		if(index >= filters.size()) {
			return;
		}
		Filter f = filters.get(index++);
		
		f.doFilter(request, response, this);
	}
}
